﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter05
{
    public class Code05
    {
        public static void Begin()
        {
            //1 b,d
            //2 详见color枚举类型，byte可以做为颜色枚举的基本类型。
            //3 
            {
                imagNum coord, temp;
                double realTemp2, arg;
                int iterations;
                for (coord.imag = 1.2; coord.imag >= -1.2; coord.imag -= 0.05)
                {
                    for (coord.real = -0.6; coord.real <= 1.77; coord.real += 0.03)
                    {
                        iterations = 0;
                        temp.real = coord.real;
                        temp.imag = coord.imag;
                        arg = (coord.real * coord.real) + (coord.imag * coord.imag);
                        while ((arg < 4) && (iterations < 40))
                        {
                            realTemp2 = (temp.real * temp.real) - (temp.imag * temp.imag) - coord.real;
                            temp.imag = (2 * temp.real * temp.imag) - coord.imag;
                            temp.real = realTemp2;
                            arg = (temp.real * temp.real) + (temp.imag * temp.imag);
                            iterations += 1;
                        }
                        switch (iterations % 4)
                        {
                            case 0:
                                Console.Write(".");
                                break;
                            case 1:
                                Console.Write("o");
                                break;
                            case 2:
                                Console.Write("O");
                                break;
                            case 3:
                                Console.Write("@");
                                break;

                        }
                    }
                    Console.Write("\n");
                }
                Console.ReadLine();
            }
            //4 不能。少了分号，数组越界，少了双引号
            //5
            {
                string myString = Console.ReadLine();
                string reversedString = null;
                for (int i = myString.Length - 1; i >= 0; i--)
                {
                    reversedString += myString[i];
                }
                Console.WriteLine("Reversed: {0}", reversedString);
                Console.ReadLine();


            }
            {
                //6
                string myString = Console.ReadLine();
                myString = myString.Replace("no", "yes");
                Console.WriteLine("Replaced \"no\" with \"yes\": {0}", myString);
                Console.ReadLine();
            }
            {
                //7 方式1
                string myString = Console.ReadLine();
                myString = "\"" + myString.Replace(" ", "\" \"") + "\"";
                Console.WriteLine("Added double quotes around words: {0}", myString);
                Console.ReadLine();
                //7 方式2
                myString = Console.ReadLine();
                string[] myWords = myString.Split(' ');
                foreach (string myWord in myWords)
                {
                    Console.Write("\"{0}\"", myWord);
                }
                Console.ReadLine();
            }
        }
    }

    public enum color : short
    {
        //红、橙、黄、绿、蓝、靛、紫、黑、白
        red,
        orange,
        yellow,
        green,
        blue,
        indigo,
        purple,
        violet,
        white,
        black,
    }

    public struct imagNum
    {
        public double real, imag;
    }
}
